/*
 ============================================================================
 Name		: TableWidget.h
 Author	  : Zhang Jiawei
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CTableWidget declaration
 ============================================================================
 */

#ifndef TABLEWIDGET_H
#define TABLEWIDGET_H

// INCLUDES
#include "ListWidget.h"

// CLASS DECLARATION

class CTableWidget: public CListWidget
{
public:
    ~CTableWidget();
    static CTableWidget* NewL(MWidgetObserver* aObserver = NULL,TBool bFirstRowFixed = ETrue, TBool bFirstColumnFixed = ETrue);
    static CTableWidget* NewLC(MWidgetObserver* aObserver = NULL,TBool bFirstRowFixed = ETrue, TBool bFirstColumnFixed = ETrue);
    
public:
    typedef enum 
    {
    	ETableEdgeEventNone,
		ETableEdgeEvent_Up,
		ETableEdgeEvent_Down,
		ETableEdgeEvent_Left,
		ETableEdgeEvent_Right,
		ETableEdgeEventCount
    }TTableEdgeEvent;
public:
    // form CControl
    virtual void Draw(CFbsBitGc& g);
    virtual TBool OnKeyDown(const TInt& keycode);
    virtual void SetRect(const TInt& left, const TInt& top, const TInt& right, const TInt& bottom);
    virtual void FocusChanged(TBool aFocus, const TInt keyCode);
    
public:
    // from MFlickableCallback
    virtual void SetScrollOffset(const TPoint& aOffset);
	//virtual TBool OnMouseUp(const TPoint& aPt);
    
public:
    // New functions
    void SetColumnCount(TInt aColumnCount);
    TInt ColumnCount() const;
    inline TInt GetSelectRow(){return iHighlight;};
    TInt GetMaxRow();
    TTableEdgeEvent GetEdgeEvent();
    
    void SetFirstRowFixed(TBool aFirstRowFixed);
    void SetFirstColumnFixed(TBool aFirstColumnFixed);
    
public:
	TWidgetItem& GetItem(TInt aRow, TInt aColumn);
    
protected:
    virtual void SetScrollBar(TInt nPos, TInt nRange);
    
private:
    CTableWidget();
    void ConstructL(MWidgetObserver* aObserver = NULL,TBool bFirstRowFixed = ETrue, TBool bFirstColumnFixed = ETrue);

    void DrawItem(CFbsBitGc& g, TWidgetItem& aItem, TRect aRect);
    void Draw1(CFbsBitGc& g);
    void Draw2(CFbsBitGc& g);
    void Draw3(CFbsBitGc& g);
    void Draw4(CFbsBitGc& g);
    
    TInt CalcMaxColumnWidth(TInt aColumn);
    TInt CalcTableWidth();
    TInt CalcTableColumnWidth(TInt nColumn);
    TInt CalcStartColumn();
    TInt CalcEndColumn();
    
public:
	TRgb iBlackgroundColor;
private:
    TInt iColumnCount;

    TInt iStartColumn;
    TInt iEndColumn;
    
    TBool iFirstRowFixed;
    TBool iFirstColumnFixed;
    TTableEdgeEvent iEdgeEvent;
    //TRect iScrollArea;
};

inline CTableWidget::TTableEdgeEvent CTableWidget::GetEdgeEvent()
{
	return iEdgeEvent;
}
inline void CTableWidget::SetColumnCount(TInt aColumnCount)
{
    iColumnCount = aColumnCount;
}

inline TInt CTableWidget::ColumnCount() const
{
    return iColumnCount;
}

#endif // TABLEWIDGET_H
